import javax.swing.*;
import java.util.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;

public class InventoryMenu extends javax.swing.JFrame {

    /** Creates new form InventoryMenu */
    public InventoryMenu() {
        initComponents();
        getDatabase();
        getCategory();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Inventory Module");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Product #", "Name", "Category ", "Price", "Stocks Left", "Reorder Level", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Add Product");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Update Product");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Enable/Disable Product");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Search by Name");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Back");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel1.setText("Search Product by Name");

        jLabel2.setText("Filter Product by Category");

        jComboBox1.setEditable(true);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<Select Category>" }));

        jButton6.setText("Filter by Selected Category");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Add Category");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Clear Search");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton10.setText("Edit Category");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jComboBox2.setEditable(true);
        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<Select Category>" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox1, 0, 173, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addComponent(jComboBox2, 0, 173, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addGap(18, 18, 18)
                .addComponent(jButton5)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
JDialog dbox = new JDialog();
    dbox.setSize(400,250);
    int response = JOptionPane.showConfirmDialog(
                    dbox, "Are you sure you want to enable/disable this product?", " ", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (response == JOptionPane.YES_OPTION ) {
        Object x = jTable1.getValueAt(jTable1.getSelectedRow(), 0);
        Object z = jTable1.getValueAt(jTable1.getSelectedRow(), 6);
        int i = Integer.parseInt((String)x);

        String j = (String)z;
        int k = 0;
        if(j.compareToIgnoreCase("enabled") == 0){
             k = 0;
        }
        else if(j.compareToIgnoreCase("disabled") == 0){
             k = 1;
        }
        disableenableData(i, k);
        this.dispose();
        InventoryMenu y = new InventoryMenu();
        y.show();
        dbox.dispose();
        }
            else if (response == JOptionPane.NO_OPTION ) {
                dbox.dispose();
            } 
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         SaveProduct x = new SaveProduct();
        x.setType(0);
        x.show();
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        Object y = jTable1.getValueAt(jTable1.getSelectedRow(), 0);
        SaveProduct z = new SaveProduct();
        int i = Integer.parseInt((String)y);
        System.out.println(i);
        z.setIndex(i);
        z.setType(1);
        this.dispose();
        z.show();
           
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
      String s = jTextField1.getText();
        boolean specflag = true;
        for (int j = 0;j < jTextField1.getText().length();j++) {
		if (!(Character.isLetterOrDigit(jTextField1.getText().charAt(j))) && !(Character.isWhitespace(jTextField1.getText().charAt(j))) && !(jTextField1.getText().charAt(j) == '-')) {
                    specflag = false;
		}
        }

        if(jTextField1.getText().length() == 0){
                 JOptionPane.showMessageDialog(null, "Search field was left blank. Please Enter Again.", "Error", JOptionPane.ERROR_MESSAGE);
        }
        else if(specflag == false){
                 JOptionPane.showMessageDialog(null, "Search field contains special characters. Please Enter Again.", "Error", JOptionPane.ERROR_MESSAGE);
        }
        else{
            searchName(s);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        String s = (String)jComboBox1.getSelectedItem();
        if(jComboBox1.getSelectedIndex() == 0){
                 JOptionPane.showMessageDialog(null, "There was no selected item in the combo box. Please Try Again.", "Error", JOptionPane.ERROR_MESSAGE);
        }
        else{
            searchCat(s);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        MainMenu x = new MainMenu();
        if(type == 1)
        x.setType(1);
        x.show();
        this.dispose();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        AddCategory x = new AddCategory();
        if(type == 1)
        x.setType(1);
        x.show();
        this.dispose();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed

        this.dispose();
        InventoryMenu x = new InventoryMenu();
        if(type == 1)
        x.setType(1);
        x.show();
        this.dispose();// TODO add your handling code here:
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
     
        String se = (String)jComboBox2.getSelectedItem();
        AddCategory EditCat = new AddCategory();
         if(jComboBox2.getSelectedIndex() == 0){
                 JOptionPane.showMessageDialog(null, "There was no selected item in the combo box. Please Try Again.", "Error", JOptionPane.ERROR_MESSAGE);
        }
        else{
        EditCat.setIndex(se);
        EditCat.setTyper(1);
        EditCat.show();
        this.dispose(); 
         }  
             
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox2ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InventoryMenu().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
DB DB = new DB();
   int rowCount = 0;
   int type = 0;

   Connection conn;
   PreparedStatement pstmt;
   Statement stmt;
   ResultSet rset;
   String query;
   int dis = 0;

     public void setType(int type){
        this.type = type;
        if(type == 1){
            jButton1.setEnabled(false);
            jButton2.setEnabled(false);
            jButton3.setEnabled(false);
            jButton7.setEnabled(false);
            jButton10.setEnabled(false);
        }
    }

   	public void getDatabase(){

            Vector row = new Vector();
            rowCount = 0;

            try {
                       DB.connect();
                       conn = DB.getConn();

                       query = "Select product.productNo, product.name, category.catname, product.price, stocks.quantity, product.status, product.reorderLevel from product, stocks, category where product.productNo = stocks.productNo AND product.categoryNo = category.categoryNo AND status = 1;";
                       pstmt = conn.prepareStatement(query);
                       rset = pstmt.executeQuery();


                       while(rset.next())
                       {
                             row.addElement(rset.getString("productNo"));
                             row.addElement(rset.getString("name"));
                             row.addElement(rset.getString("catname"));
                             row.addElement(rset.getString("price"));
                             row.addElement(rset.getString("quantity"));
                             row.addElement(rset.getString("reorderLevel"));
                             int x = rset.getInt("status");
                             if(x == 0){
                                 row.addElement("disabled");
                                 dis++;
                             }
                             else {
                                 row.addElement("enabled");
                             }

                             rowCount++;
                             
                       }

                    DB.disconnect();
                    pstmt.close();

             } catch (Exception ex) {
                   JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
             }
            getDatabase2(rowCount, row);

       }

       public void getDatabase2(int rowCount, Vector row){

            try {
                       DB.connect();
                       conn = DB.getConn();

                       query = "Select product.productNo, product.name, category.catname, product.price, stocks.quantity, product.status, product.reorderLevel from product, stocks, category where product.productNo = stocks.productNo AND product.categoryNo = category.categoryNo AND status = 0;";
                       pstmt = conn.prepareStatement(query);
                       rset = pstmt.executeQuery();


                       while(rset.next())
                       {
                             row.addElement(rset.getString("productNo"));
                             row.addElement(rset.getString("name"));
                             row.addElement(rset.getString("catname"));
                             row.addElement(rset.getString("price"));
                             row.addElement(rset.getString("quantity"));
                             row.addElement(rset.getString("reorderLevel"));
                             int x = rset.getInt("status");
                             if(x == 0){
                                 row.addElement("disabled");
                                 dis++;
                             }
                             else {
                                 row.addElement("enabled");
                             }

                             rowCount++;

                       }
                       setValues(row, rowCount);
                    DB.disconnect();
                    pstmt.close();

             } catch (Exception ex) {
                   JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
             }

       }

       public void getCategory(){

            try {
                       DB.connect();
                       conn = DB.getConn();

                       query = "Select * from category";
                       pstmt = conn.prepareStatement(query);
                       rset = pstmt.executeQuery();


                       while(rset.next())
                       {
                             jComboBox1.addItem(rset.getString("catname"));
                             jComboBox2.addItem(rset.getString("catname"));
                       }
                    DB.disconnect();
                    pstmt.close();

             } catch (Exception ex) {
                   JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
             }

       }

       public void setValues(Vector row, int rowCount){
            Object z[] = {null,null,null,null,null,null,null};
            DefaultTableModel model = (javax.swing.table.DefaultTableModel)jTable1.getModel();
            jTable1.setModel(model);

            if(rowCount > 24){
                int q = rowCount - 24;
                for(int w = 0; w < q; w++){
                    model.addRow(z);
                }
            }
       		int columnNum = 0;
       		for(int i = 1; i <= rowCount; i++){
			for(columnNum = 0; columnNum < 7; columnNum++){
       		jTable1.setValueAt(row.elementAt(columnNum+(7*(i-1))), i-1, columnNum);}
       		columnNum = 0;}
       }
       public void clearValues(int rowCount, int dis){

       		int columnNum = 0;
       		for(int i = 1; i <= rowCount+dis; i++){
			for(columnNum = 0; columnNum < 7; columnNum++){
       		jTable1.setValueAt("", i-1, columnNum);}
       		columnNum = 0;}
       }

       public void disableenableData(int i, int j)
      {

            try {

            		DB.connect();
            		conn = DB.getConn();

                      query = "update product set status = "+j+" where productNo = '"+i+"';";

                      pstmt = conn.prepareStatement(query);

                      pstmt.executeUpdate();

                   DB.disconnect();
                   pstmt.close();


            } catch (Exception ex) {
            		  JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }

            getDatabase();
      }

      public void searchName(String s)
      {
            Vector row = new Vector();
            clearValues(rowCount,dis);
            rowCount = 0;
            System.out.println(type);
            System.out.println(s);
            try {

                       DB.connect();
                       conn = DB.getConn();

                       query = "select product.productNo, product.name, category.catname, product.price, stocks.quantity, product.reorderLevel, product.status from product, stocks, category where product.name = '"+s+"' AND product.productNo = stocks.productNo AND product.categoryNo = category.categoryNo;";
                       pstmt = conn.prepareStatement(query);
                       rset = pstmt.executeQuery();

                       while(rset.next())
                       {
                           
                             row.addElement(rset.getString("productNo"));
                             row.addElement(rset.getString("name"));
                             row.addElement(rset.getString("catname"));
                             row.addElement(rset.getString("price"));
                             row.addElement(rset.getString("quantity"));
                             row.addElement(rset.getString("reorderLevel"));
                             int x = rset.getInt("status");
                             if(x == 0){
                                 row.addElement("disabled");
                             }
                             else {
                                 row.addElement("enabled");
                             }

                             rowCount++;
                       }
                             setValues(row, rowCount);
                   DB.disconnect();
                   pstmt.close();

                   if(row.isEmpty() == true){
                       JOptionPane.showMessageDialog(null, "No Results Found.", "Search",JOptionPane.WARNING_MESSAGE);
                   }

            } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
      }

      public void searchCat(String s)
      {
            Vector row = new Vector();
            clearValues(rowCount,dis);
            rowCount = 0;
            System.out.println(type);
            System.out.println(s);
            try {

                       DB.connect();
                       conn = DB.getConn();

                       query = "select product.productNo, product.name, category.catname, product.price, stocks.quantity, product.reorderLevel, product.status from product, stocks, category where category.catname = '"+s+"' AND product.productNo = stocks.productNo AND product.categoryNo = category.categoryNo;";
                       pstmt = conn.prepareStatement(query);
                       rset = pstmt.executeQuery();

                       while(rset.next())
                       {
                             row.addElement(rset.getString("productNo"));
                             row.addElement(rset.getString("name"));
                             row.addElement(rset.getString("catname"));
                             row.addElement(rset.getString("price"));
                             row.addElement(rset.getString("quantity"));
                             row.addElement(rset.getString("reorderLevel"));
                             int x = rset.getInt("status");
                             if(x == 0){
                                 row.addElement("disabled");
                             }
                             else {
                                 row.addElement("enabled");
                             }

                             rowCount++;
                       }
                             setValues(row, rowCount);
                   DB.disconnect();
                   pstmt.close();

                   if(row.isEmpty() == true){
                       JOptionPane.showMessageDialog(null, "No Results Found.", "Search",JOptionPane.WARNING_MESSAGE);
                   }

            } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
      }
}
